package main

import (
	"web/dealfunc"
	"github.com/gin-gonic/gin"
)

// 处理 CORS 的中间件
func CORS() gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
		c.Writer.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
		c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type")

		if c.Request.Method == "OPTIONS" {
			c.AbortWithStatus(204)
			return
		}

		c.Next()
	}
}

func main() {
	r := gin.Default()

	r.Use(CORS())

	r.POST("/login", dealfunc.CheckInf)
	r.GET("/comment/get", dealfunc.GetComment)
	r.POST("/comment/add", dealfunc.AddComment)

	r.Run(":8080")
}